package com.foreveross.crawl.web.controller.monitor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hornetq.core.logging.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.foreveross.crawl.application.impl.computer.ComputerInstanceByStrategy;
import com.foreveross.crawl.vo.MachineInfo;
import com.foreveross.crawl.vo.Message;
import com.foreveross.crawl.web.controller.auth.BaseController;

@Controller
@RequestMapping("/monitor/Computer")
public class ComputerController extends BaseController {

	private static Logger logger = Logger.getLogger(ComputerController.class);
	
	@ResponseBody
	@RequestMapping("/obtainMachineInfo")
	public Map<String, Object> obtainMachineInfo(){
		Map<String, Object> dataMap = new HashMap<String, Object>();
		try {
			Message message = ComputerInstanceByStrategy.getInstance().getComputerMessage();
			@SuppressWarnings("unchecked")
			MachineInfo machineInfo = ((List<MachineInfo>)message.getBody()).get(0);
			dataMap.put("data", machineInfo);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return dataMap;
	}
}
